/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * inicial.java
 *
 * Created on 31-mar-2009, 17:56:20
 */

package laboratorio;
import clientes.Cliente;
import com.lowagie.text.DocumentException;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import com.mysql.jdbc.jdbc2.optional.MysqlXAConnection;
import emailSW.MailUtils;
import empresa.DatosEmpresa;
import javax.persistence.Query;
import tarifas.ImprimirProductos;
import java.awt.Color;
import java.awt.Graphics;
import java.io.File;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.print.DocFlavor.STRING;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
/**
 *
 * @author rocio
 */
public class inicial extends javax.swing.JFrame {
    private Cliente cliente;
    private Query q;
    /** Creates new form inicial */
    public inicial() {
        initComponents();

    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        lpdPUEntityManager = java.beans.Beans.isDesignTime() ? null : javax.persistence.Persistence.createEntityManagerFactory("lpdPU").createEntityManager();
        productoQuery = java.beans.Beans.isDesignTime() ? null : lpdPUEntityManager.createQuery("SELECT p FROM Producto p");
        productoList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : productoQuery.getResultList();
        clienteQuery = java.beans.Beans.isDesignTime() ? null : lpdPUEntityManager.createQuery("SELECT c FROM Cliente c");
        clienteList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : clienteQuery.getResultList();
        datosEmpresaQuery = java.beans.Beans.isDesignTime() ? null : lpdPUEntityManager.createQuery("SELECT d FROM DatosEmpresa d");
        datosEmpresaList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : datosEmpresaQuery.getResultList();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();
        jButton7 = new javax.swing.JButton();
        jButton8 = new javax.swing.JButton();
        jButton9 = new javax.swing.JButton();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenu2 = new javax.swing.JMenu();
        jMenu3 = new javax.swing.JMenu();
        jMenu4 = new javax.swing.JMenu();
        jMenu5 = new javax.swing.JMenu();
        jMenu6 = new javax.swing.JMenu();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(laboratorio.LaboratorioApp.class).getContext().getResourceMap(inicial.class);
        setTitle(resourceMap.getString("Form.title")); // NOI18N
        setBackground(resourceMap.getColor("Form.background")); // NOI18N
        setForeground(resourceMap.getColor("Form.foreground")); // NOI18N
        setName("Form"); // NOI18N

        jButton1.setFont(resourceMap.getFont("jButton1.font")); // NOI18N
        jButton1.setForeground(resourceMap.getColor("jButton1.foreground")); // NOI18N
        jButton1.setMnemonic('/');
        jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
        jButton1.setName("jButton1"); // NOI18N
        jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                verTrabajoaPend(evt);
            }
        });

        jButton2.setFont(resourceMap.getFont("jButton2.font")); // NOI18N
        jButton2.setIcon(resourceMap.getIcon("jButton2.icon")); // NOI18N
        jButton2.setText(resourceMap.getString("jButton2.text")); // NOI18N
        jButton2.setName("jButton2"); // NOI18N
        jButton2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                verTrabajos(evt);
            }
        });

        jButton3.setFont(resourceMap.getFont("jButton3.font")); // NOI18N
        jButton3.setIcon(resourceMap.getIcon("jButton3.icon")); // NOI18N
        jButton3.setText(resourceMap.getString("jButton3.text")); // NOI18N
        jButton3.setName("jButton3"); // NOI18N
        jButton3.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                verAlbaranes(evt);
            }
        });

        jButton4.setFont(resourceMap.getFont("jButton4.font")); // NOI18N
        jButton4.setIcon(resourceMap.getIcon("jButton4.icon")); // NOI18N
        jButton4.setText(resourceMap.getString("jButton4.text")); // NOI18N
        jButton4.setName("jButton4"); // NOI18N
        jButton4.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                verFacturas(evt);
            }
        });

        jButton5.setFont(resourceMap.getFont("jButton5.font")); // NOI18N
        jButton5.setIcon(resourceMap.getIcon("jButton5.icon")); // NOI18N
        jButton5.setText(resourceMap.getString("jButton5.text")); // NOI18N
        jButton5.setName("jButton5"); // NOI18N
        jButton5.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                verResumenFac(evt);
            }
        });

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(laboratorio.LaboratorioApp.class).getContext().getActionMap(inicial.class, this);
        jButton6.setAction(actionMap.get("quit")); // NOI18N
        jButton6.setFont(resourceMap.getFont("jButton6.font")); // NOI18N
        jButton6.setIcon(resourceMap.getIcon("jButton6.icon")); // NOI18N
        jButton6.setText(resourceMap.getString("jButton6.text")); // NOI18N
        jButton6.setName("jButton6"); // NOI18N

        jButton7.setFont(resourceMap.getFont("jButton7.font")); // NOI18N
        jButton7.setIcon(resourceMap.getIcon("jButton7.icon")); // NOI18N
        jButton7.setText(resourceMap.getString("jButton7.text")); // NOI18N
        jButton7.setName("jButton7"); // NOI18N
        jButton7.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                verPresupuestos(evt);
            }
        });

        jButton8.setFont(resourceMap.getFont("jButton8.font")); // NOI18N
        jButton8.setIcon(resourceMap.getIcon("jButton8.icon")); // NOI18N
        jButton8.setText(resourceMap.getString("jButton8.text")); // NOI18N
        jButton8.setName("jButton8"); // NOI18N
        jButton8.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                verProductos(evt);
            }
        });

        jButton9.setFont(resourceMap.getFont("jButton9.font")); // NOI18N
        jButton9.setIcon(resourceMap.getIcon("jButton9.icon")); // NOI18N
        jButton9.setText(resourceMap.getString("jButton9.text")); // NOI18N
        jButton9.setName("jButton9"); // NOI18N
        jButton9.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                verClientes(evt);
            }
        });

        jMenuBar1.setName("jMenuBar1"); // NOI18N

        jMenu1.setText(resourceMap.getString("jMenu1.text")); // NOI18N
        jMenu1.setName("jMenu1"); // NOI18N
        jMenu1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                verDatosEmpresa(evt);
            }
        });
        jMenuBar1.add(jMenu1);

        jMenu2.setText(resourceMap.getString("jMenu2.text")); // NOI18N
        jMenu2.setName("jMenu2"); // NOI18N
        jMenu2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                verCopia(evt);
            }
        });
        jMenuBar1.add(jMenu2);

        jMenu3.setText(resourceMap.getString("jMenu3.text")); // NOI18N
        jMenu3.setName("jMenu3"); // NOI18N
        jMenu3.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                Doctores(evt);
            }
        });
        jMenuBar1.add(jMenu3);

        jMenu4.setText(resourceMap.getString("jMenu4.text")); // NOI18N
        jMenu4.setName("jMenu4"); // NOI18N

        jMenu5.setText(resourceMap.getString("jMenu5.text")); // NOI18N
        jMenu5.setName("jMenu5"); // NOI18N
        jMenu5.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                imprimirtarifa(evt);
            }
        });
        jMenu4.add(jMenu5);

        jMenu6.setText(resourceMap.getString("jMenu6.text")); // NOI18N
        jMenu6.setName("jMenu6"); // NOI18N
        jMenu6.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                enviartarifa(evt);
            }
        });
        jMenu4.add(jMenu6);

        jMenuBar1.add(jMenu4);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(127, 127, 127)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jButton3)
                                    .addComponent(jButton4)))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addContainerGap(191, Short.MAX_VALUE)
                                .addComponent(jButton5)
                                .addGap(127, 127, 127)))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(102, 102, 102)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jButton7)
                                    .addComponent(jButton8)))
                            .addGroup(layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jButton6, javax.swing.GroupLayout.PREFERRED_SIZE, 216, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(284, 284, 284)
                        .addComponent(jButton2)
                        .addGap(74, 74, 74)
                        .addComponent(jButton9)))
                .addContainerGap(154, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addGap(398, 398, 398)
                .addComponent(jButton1)
                .addContainerGap(429, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(32, 32, 32)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButton9, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(43, 43, 43)
                        .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                    .addComponent(jButton8, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(16, 16, 16)
                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(8, 8, 8)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton7, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(48, 48, 48)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jButton6, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton5, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(80, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void verTrabajoaPend(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_verTrabajoaPend
        TrabajosPendientes t = new TrabajosPendientes();
        t.setVisible(true);
}//GEN-LAST:event_verTrabajoaPend

    private void verClientes(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_verClientes
        Clientes c= new Clientes();
        c.setVisible(true);
       
}//GEN-LAST:event_verClientes

    private void verProductos(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_verProductos
        Productos p= new Productos();
        p.setVisible(true);
}//GEN-LAST:event_verProductos

    private void verPresupuestos(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_verPresupuestos
        Presupuestos p= new Presupuestos();
        p.setVisible(true);
}//GEN-LAST:event_verPresupuestos

    private void verTrabajos(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_verTrabajos
        Trabajos t=new Trabajos();
        t.setVisible(true);
}//GEN-LAST:event_verTrabajos

    private void verAlbaranes(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_verAlbaranes
        Albaranes a= new Albaranes();
        a.setVisible(true);
    }//GEN-LAST:event_verAlbaranes

    private void verFacturas(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_verFacturas
        Facturas f=new Facturas();
        f.setVisible(true);
    }//GEN-LAST:event_verFacturas

    private void verResumenFac(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_verResumenFac
        ResumenFacturacion rf=new ResumenFacturacion();
        rf.setVisible(true);
    }//GEN-LAST:event_verResumenFac

    private void verDatosEmpresa(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_verDatosEmpresa
        DatosDeLaEmpresa ventana = new DatosDeLaEmpresa();
        ventana.setVisible(true);
    }//GEN-LAST:event_verDatosEmpresa

    private void Doctores(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_Doctores
        Doctores doc=new Doctores();
        doc.setVisible(true);
}//GEN-LAST:event_Doctores

    private void verCopia(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_verCopia
        CopiaSeg cop=new CopiaSeg();
        cop.setVisible(true);

    }//GEN-LAST:event_verCopia

    private void imprimirtarifa(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_imprimirtarifa
        
            try {
                ImprimirProductos ip = new ImprimirProductos();
            } catch (Exception ex) {
                Logger.getLogger(inicial.class.getName()).log(Level.SEVERE, null, ex);
            }
        
}//GEN-LAST:event_imprimirtarifa

    private void enviartarifa(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_enviartarifa
        // TODO add your handling code here:
        File f=new File("C:\\Users\\Juan Antonio Tirado\\Documents\\NetBeansProjects\\trunk\\laboratorio\\Tarifas.pdf");
        
        if(!f.exists()){
            JOptionPane.showMessageDialog(this, "primero debe imprimir la tarifa");
        }else{
        Iterator itc=clienteList.iterator();
        while(itc.hasNext()){
            try {
                cliente = (Cliente) itc.next();
                q = lpdPUEntityManager.createQuery("SELECT d FROM DatosEmpresa d");
                List aa = q.getResultList();
                DatosEmpresa datosempresa = (DatosEmpresa) aa.get(0);
                String de = datosempresa.getEmail();
                String asunto = "Tarifas de precios";
                String contenido = "Pasamos a enviarle las tarifas de precios de nuestros productos";
                //String para=cliente.getEmail();
                String para = "tiradogonzalezveronica@gmail.com";
                String tit = "Tarifas.pdf";

                String archivo = "C:\\Users\\Juan Antonio Tirado\\Documents\\NetBeansProjects\\trunk\\laboratorio\\".concat(tit);
                MailUtils j = new MailUtils();
                j.sendMail(asunto, contenido, de, para, archivo);
            } catch (Exception ex) {
                Logger.getLogger(inicial.class.getName()).log(Level.SEVERE, null, ex);
            }
        }}
    }//GEN-LAST:event_enviartarifa

   
    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new inicial().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private java.util.List<clientes.Cliente> clienteList;
    private javax.persistence.Query clienteQuery;
    private java.util.List<empresa.DatosEmpresa> datosEmpresaList;
    private javax.persistence.Query datosEmpresaQuery;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton7;
    private javax.swing.JButton jButton8;
    private javax.swing.JButton jButton9;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JMenu jMenu4;
    private javax.swing.JMenu jMenu5;
    private javax.swing.JMenu jMenu6;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.persistence.EntityManager lpdPUEntityManager;
    private java.util.List<productos.Producto> productoList;
    private javax.persistence.Query productoQuery;
    // End of variables declaration//GEN-END:variables

}
